home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 098 (1990-12)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 098 (1990-12)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / XLisp-Stat / Book / sqrt.lsp < prev    next >
Lisp/Scheme  |  1990-10-11  |  289b  |  13 lines

  1. ; book p.83
  2.  
  3. (defun sqrt-iter (guess x)
  4.   (if (good-enough-p guess x)
  5.       guess
  6.       (sqrt-iter (improve guess x) x)))
  7.  
  8. (defun improve (guess x) (mean (list guess (/ x guess))))
  9.  
  10. (defun good-enough-p (guess x)
  11.   (< (abs (- (* guess guess) x)) .001))
  12.  
  13. (defun my-sqrt (x) (sqrt-iter 1 x))